home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Technical Docs / Apple II Technical Notes / Technical Notes (Text) / IIGS / TN.IIGS.071 < prev    next >
Encoding:
Text File  |  1990-05-29  |  6.5 KB  |  182 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIgs
  7. #71:    DA Tips and Techniques
  8.  
  9. Revised by:    Dave "DAs are a significant part of my 'life'" Lyons  May 1990
  10. Written by:    Dave Lyons                                       November 1989
  11.  
  12. This Technical Note presents tips and techniques for writing Desk Accessories.
  13. Changes since March 1990:  Added a caution against drawing during mouseUp 
  14. events in NDAs.
  15. _____________________________________________________________________________
  16.  
  17. Classic Desk Accessory Tips and Techniques
  18.  
  19. Reading the Keyboard
  20.  
  21. For a CDA that runs only under GS/OS, the Console Driver is the best choice 
  22. for reading from the keyboard.  Other CDAs have two cases to deal with:  the 
  23. Event Manager may or may not be started.  The Text Tools can read the keyboard 
  24. in either case, but you should avoid using the Text Tools whenever possible 
  25. (see Apple IIgs Technical Note #69, The Ins and Outs of Slot Arbitration).
  26.  
  27. You can call EMStatus to determine whether the Event Manager is started.  When 
  28. it is, you can read keypresses by calling GetNextEvent.  When the Event 
  29. Manager is not started, you can read keys directly from the keyboard hardware 
  30. by waiting for bit 7 of location $E0C000 to turn on.  When it does, the lower 
  31. seven bits represent the key pressed.  Once you've detected a keypress, you 
  32. need to write to location $E0C010 to remove the keypress from the buffer.
  33.  
  34. Alternately, you can use IntSource (in the Miscellaneous Tools) to temporarily 
  35. disable keyboard interrupts and then read the keyboard hardware directly.  Be 
  36. sure to reactivate keyboard interrupts if, and only if, they were previously 
  37. enabled.
  38.  
  39. Just One Page of Stack Space
  40.  
  41. CDAs normally have only a single page of stack space available to them (256 
  42. bytes at $00/01xx).  Your CDA may or may not be able to allocate additional 
  43. stack space from bank 0 during execution.  The following code (written for the 
  44. MPW IIgs cross-assembler) shows a safe way to try to allocate more stack space 
  45. and to switch between stacks when the space is available.
  46.  
  47. If ProDOS 8 is active, your CDA cannot allocate additional space (and there is 
  48. no completely safe way to "borrow" bank 0 space from the ProDOS 8 
  49. application).
  50.  
  51.  
  52. HowMuchStack gequ $1000              ;try for 4K of stack space
  53.  
  54. start        phd
  55.              phb
  56.              phk
  57.              plb
  58.              pha                     ;Space for result
  59.              pha
  60.              PushLong #HowMuchStack
  61.              pha
  62.              _MMStartUp
  63.              pla
  64.              ora #$0f00              ;OR in an arbitrary auxiliary ID
  65.              pha
  66.              PushWord #$C001         ;fixed, locked, use specified bank
  67.              PushLong #0             ;(specify bank 0)
  68.              _NewHandle
  69.              tsc
  70.              sta theOldStack
  71.              bcs NoStackSpace        ;still set from _NewHandle
  72.              tcd
  73.              lda [1]
  74.              tcd
  75. ;            clc                     ;carry is already clear
  76.              adc #HowMuchStack-1
  77. NoStackSpace pha
  78.              ldx #$fe
  79. keepStack    lda >$000100,x
  80.              sta stackImage,x
  81.              dex
  82.              dex
  83.              bpl keepStack
  84.              pla
  85.              tcs
  86.              jsl RealCDAentry        ;carry is clear if large stack available
  87.              php
  88.              php
  89.              pla
  90.              sta pRegister
  91.              sei
  92.              ldx #$fe
  93.  
  94. restoreStack lda stackImage,x
  95.              sta >$000100,x
  96.              dex
  97.              dex
  98.              bpl restoreStack
  99.              lda theOldStack
  100.              tcs
  101.              lda pRegister
  102.              pha
  103.              plp
  104.              plp
  105.  
  106.              lda 1,s
  107.              ora 3,s
  108.              beq noDispose
  109.              _DisposeHandle
  110.              bra Exit
  111. noDispose    pla
  112.              pla
  113.  
  114.  
  115. Exit         plb
  116.              pld
  117.              rtl
  118.  
  119. pRegister    ds 2
  120. theOldStack  ds 2
  121. stackImage   ds.b 256
  122.  
  123. When this routine calls RealCDAentry, the carry flag is set if no extra stack 
  124. space is available.  If the carry is clear, the additional stack space was 
  125. available and the direct-page register points to the bottom of that space.
  126.  
  127. RealCDAentry bcs smallStack      ;if c set, only 1 page of stack is available
  128.              ...                 ; put something interesting here
  129.              rtl
  130.  
  131. smallStack   _SysBeep
  132.              rtl
  133.  
  134. Note that interrupts are disabled while the page-one stack is being restored; 
  135. they are reenabled (if they were originally enabled) only after the stack 
  136. pointer is safely back in page one.
  137.  
  138.  
  139. New Desk Accessory Tips and Techniques
  140.  
  141. NDAs May Not Receive Apple- Keystrokes
  142.  
  143. NDAs are not guaranteed to receive key-down events with the Apple key down.  
  144. It is possible that future System Software will pass keystrokes directly to 
  145. the application when the Apple key is down, even if a NDA window is in front.
  146.  
  147. Calling InstallNDA From Within an NDA
  148.  
  149. It is possible to write an NDA that installs other NDAs.  However, with System 
  150. Software 5.0 and later, InstallNDA returns an error when called from an NDA.  
  151. When your NDA has control because the Desk Manager called one of your NDA's 
  152. entry points, the Desk Manager's data structures are already in use, so 
  153. InstallNDA is unable to modify them.
  154.  
  155. The solution is to use SchAddTask in the Scheduler to postpone the InstallNDA 
  156. call until the system is not busy.  Remember that the Bank and Direct Page 
  157. registers are not defined when your scheduled task is executed.
  158.  
  159. Processing mouseUp events
  160.  
  161. When an NDA's action routine receives a mouseUp event, it is not always safe 
  162. for the NDA to draw in its window.
  163.  
  164. For example, when the user drags an NDA window, the NDA receives the mouseUp 
  165. before the window is actually moved, and before DragWindow erases the outline 
  166. of the new window position, which may overlap the window's content.  In 
  167. addition, when the user chooses a menu item, the front NDA receives the 
  168. mouseUp before the menu's image is removed, and the image may overlap the 
  169. NDA's window.  In either case, drawing in the window makes a mess.
  170.  
  171. The solution is to avoid drawing in direct response to a mouseUp.  Instead, 
  172. invalidate part of the window to force an update event to happen later.
  173.  
  174.  
  175. Further Reference
  176. _____________________________________________________________________________
  177.   o  Apple IIGS Toolbox Reference, Volumes 1 & 3
  178.   o  GS/OS Reference
  179.   o  Apple IIGS Hardware Reference
  180.   o  Apple IIGS Technical Note #69, The Ins and Outs of Slot Arbitration
  181.  
  182.